package com.ytzl.gotrip.rpc.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.ytzl.gotrip.rpc.api.RpcSendEmailService;
import com.ytzl.gotrip.rpc.api.RpcSendMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
@Service(interfaceClass = RpcSendEmailService.class)
public class RpcSendEmailServiceImpl implements RpcSendEmailService {
    @Autowired
    private JavaMailSender mailSender;
    //邮件发件人
    @Value("${mail.fromMail.addr}")
    private String from;




    @Override
    public void sendEmail(String to, String subject, String verifyCode) {
        System.out.println("邮件已发送");
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(to);
        message.setSubject("四六级发牢骚十来分家里是圣灵丹方剂我饿额是劳动法微积分goitrip验证码为：请勿转发");
        message.setText("您的激活码为："+verifyCode);

        try {
            mailSender.send(message);
            //logger.info("简单邮件已经发送。");
            System.out.println("邮件已发送");
        } catch (Exception e) {
            e.printStackTrace();
            //logger.error("发送简单邮件时发生异常！", e);System.out.println("邮件已发送");
            System.err.println("发送失败");
        }
    }
}
